﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HospitalSystem.Core;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
namespace HospitalSystem
{
    public partial class showcidinfo2 : System.Web.UI.Page
    {

        private show_Image _showimage;
        private findchildLog _fc;
        private GroupsLog _group;
        protected void Page_Load(object sender, EventArgs e)
        {
            showsession();
            _showimage = new show_Image();
            _showimage.show_Images(cid_label, Image1);
            _fc = new findchildLog();
            _group = new GroupsLog();
        }
        protected void showsession()
        {
            String ShowValue = (string)Session["CID"];
            cid_label.Text = ShowValue;
            String ShowValue2 = (string)Session["LastName"];
            lname.Text = ShowValue2;

            String ShowValue3 = (string)Session["FirstName"];
            fname.Text = ShowValue3;


            String ShowValue4 = (string)Session["CID"];
            SelectStat.Text = ShowValue4;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            checkcaseno();
            //_group.crepsnumber(HostID, StaffID);
            //_group.psnumbertolabel(psnumber);
            //sendsessionpsnumber();
            //sendsession();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/servicerecordindex.aspx");
        }


        protected void sendsessionpsnumber()
        {
            Session["PSNumber01"] = psnumber.Text;


        }


        protected void sendsession()
        {
            Session["CID"] = SelectStat.Text;
            Session["FirstName"] = fname.Text;
            Session["LastName"] = lname.Text;


            _fc.Bindcase(SelectStat, caseno);


            Session["CaseNo"] = caseno.Text;
            _fc.creDetails(SelectStat, caseno, psnumber);
            Response.Redirect("~/servicerecord2.aspx");



        }



        protected void checkcaseno()
        {


            string constr = WebConfigurationManager.ConnectionStrings["strconnection"].ConnectionString;
            SqlConnection scon = new SqlConnection(constr);
            //ต้องการแก้เคสที่มีอยู่แล้ว
            scon.Open();
            SqlCommand cmd = new SqlCommand("SELECT CID from Evaluation where CID = @sj", scon);
            cmd.Parameters.AddWithValue("@sj", cid_label.Text);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read() != false)
            {

                _group.crepsnumber(HostID, StaffID);
                _group.psnumbertolabel(psnumber);
                sendsessionpsnumber();
                sendsession();
              
            }

            else
            {

                MessageBox("เด็กรายได้ยังไม่ได้ทำการคัดกรองเราจะพาคุณไปหน้าทำการคัดกรอง", "cal.aspx");

            }
            reader.Close();

        }
        private void MessageBox(string msg, string urld)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "');" + "window.location.href='" + urld + "';" + "</script>";
            Page.Controls.Add(lbl);
        }
    }
}